<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src="jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <meta charset="UTF-8">
    <title class="text-center">选课页面</title>
</head>
<body>

<form class="form-signin" th:action="@{/chooseCourse}">
    <table class="table table-striped table-bordered table-hover table-condensed">
        <thead>
        <tr>
            <th>课程号</th>
            <th>课程名</th>
            <th>是否选择</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="course:${courses}">
            <td th:text="${course.getCno()}"></td>
            <td th:text="${course.getCname()}"></td>
            <td>
                <input id="checkbox" name="checkbox" type="checkbox" th:value="${course.getCno()}">
            </td>
        </tr>
        </tbody>
    </table>

    <button type="submit" onclick="checkboxResult()">提交选课结果</button>
</form>





<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type=" text/javascript">
    function checkboxResult(){
        var checkID=[];
        var Sno = JSON.stringify(window.localStorage.getItem("Sno"))
        $("input[name='checkbox']:checked").each(function(i){
            checkID[i] = $(this).val();
        });

        console.log(checkID)
        $.ajax(
            {
                type:'post',
                url:'/chooseCourse',
                data:{
                    checkID:JSON.stringify(checkID),
                    Sno:JSON.stringify(Sno)
                },
                success: function(){
                    window.location.href="/getSelectInformation"
                },
                error: function (returnValue) {
                    alert("对不起！数据加载失败！");
                },
                // contentType: "application/json;charset=utf-8",
                // traditional:true
            }
        );
    }
</script>

</body>
</html>

